<script setup lang="ts">
import { onMounted } from 'vue'
import { useUserStore } from './store/user'
import { useRouter } from 'vue-router'
import { addRoutes } from './router'

const userStore = useUserStore()
const router = useRouter()

onMounted(async () => {
  // 如果有token，初始化路由
  if (userStore.token && !userStore.hasUserInfo) {
    try {
      await userStore.getUserInfoAction()
      const routes = await userStore.getRoutesAction()
      addRoutes(routes)
    } catch (error) {
      await userStore.logout()
      router.push('/login')
    }
  }
})
</script>

<template>
  <router-view />
</template>

<style scoped>
.logo {
  height: 6em;
  padding: 1.5em;
  will-change: filter;
  transition: filter 300ms;
}
.logo:hover {
  filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vue:hover {
  filter: drop-shadow(0 0 2em #42b883aa);
}
</style>
